package gui.rejestracja;

import guiTegoNieBedzie.TableZleceniaModel;
import guiTegoNieBedzie.ZlecenieLOG;

import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.LayoutStyle;
import managers.GuiManager; 

public class ZakladkaZlecenia extends JPanel 
{
	private JButton dodajZlecenieButton;
	private JScrollPane zlecenieTabelaScrollPane1;
	private JTable zlecenieTabelaTable;
	private Window mainWindow;
	private GuiManager guiManager;
	private static final long serialVersionUID = -5760636031353824805L;

	public ZakladkaZlecenia(Window rejestracjaGUI, GuiManager guiManager) 
	{
		this.mainWindow = rejestracjaGUI;
		this.guiManager = guiManager;
		initComponents();
	}
	private void initComponents() 
	{
		dodajZlecenieButton = new JButton();
		zlecenieTabelaScrollPane1 = new JScrollPane();
		zlecenieTabelaTable = new JTable();

		dodajZlecenieButton.setText("Dodaj nowe zlecenie");
		dodajZlecenieButton.addActionListener(
				new java.awt.event.ActionListener() 
				{
					public void actionPerformed(java.awt.event.ActionEvent evt) 
					{
						dodajZlecenieButtonActionPerformed(evt);
					}
				}
		);

		printTabelaZlecen( false );
		zlecenieTabelaScrollPane1.setViewportView(zlecenieTabelaTable);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
						.addGroup(
								layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(
										layout.createSequentialGroup()
										.addGap(21, 21, 21)
										.addComponent(dodajZlecenieButton)
								)
								.addGroup(
										layout.createSequentialGroup()
										.addGap(21, 21, 21)
										.addComponent(zlecenieTabelaScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 680, Short.MAX_VALUE)
								)
						)
						.addContainerGap(20, 20)
				)
		);
		
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 
						layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(zlecenieTabelaScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 25, 25)
						.addComponent(dodajZlecenieButton)
						.addGap(10, 25, Short.MAX_VALUE)
				)
		);
	}
	public void printTabelaZlecen(boolean repaint) 
	{
		zlecenieTabelaTable.setModel( new TableZleceniaModel( new ZlecenieLOG().getListaZlecen() ) );
		if(repaint)
		{
			zlecenieTabelaTable.repaint();
		}
	}
	private void dodajZlecenieButtonActionPerformed(java.awt.event.ActionEvent evt) 
	{
		this.guiManager.pokazPanelRejestracjiProbki(this.mainWindow, this);
		//new PanelRejestracjiProbki( this.mainWindow, this ).setVisible( true );		
	}
}
